<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <title>二十一点</title>
    <link rel="stylesheet" href="./caogao.css">
    <style>
        * {
            background: none;
            border: none;
            color: rgb(61, 197, 140);
        }
        
        body {
            background-color: #4c2364;
            text-align: center
        }
        
        #uip button {
            transition: 0.5s;
        }
        
        #uip button:hover {
            color: rgb(61, 197, 174);
        }
        
        #aa {
            position: absolute;
            left: 0;
            top: 1px;
            font-size: 20px;
        }
    </style>
    <script>
        ug = cgg = 0;
        i = function(a) {
            return document.getElementById(a);
        }

        function aip() {
            if (ug >= 21) {
                uok();
            }
        }

        howToPlay = function() {
            alert(
                `感谢游玩！
按下add键你的示数会随机增加1-13
当值≥21会自动停止
按下re清空你的值
按下ok停止

电脑生成规则：生成期盼值（在此说明编写是期盼值为13~17），然后尝试抽到大于等于期盼值返回（其余自行翻找JS'cg()'函数）

源码：
https://www.gitee.com/xijetxiaojun/d21/
效果：
http://xijetxiaojun.gitee.io/d21

Return from cd():
${cg()}`
            );
        };

        function inp(a) {
            switch (a) {
                case 1:
                    ug += (Math.floor(Math.random() * 13) + 1);
                    i("ab").innerHTML = ug;
                    aip();
                    break;
                case 2:
                    ug = 0;
                    i("ab").innerHTML = 0;
                    break;
                case 3:
                    uok();
                    break;
            }
            i("uip").style.transition = "100ms cubic-bezier(0.15, 0.46, 0, 0.92)";
            i("uip").style.opacity = 0.7;
            setTimeout(function() {
                i("uip").style.transition = "0.3s cubic-bezier(0.15, 0.46, 0, 0.92)";
                i("uip").style.opacity = 1;
            }, 100)
        }

        function cg() {
            exp = 13 + Math.floor(Math.random() * 4);
            cgg = 0;
            while (cgg <= exp) {
                cgg += (Math.floor(Math.random() * 13) + 1);
            }
            return cgg;
        }

        er = function(a) { //endReturn
            var rt = 0;
            switch (a) {
                case 1:
                    var rt = "人赢";
                    break;
                case 2:
                    var rt = "人输";
                    break;
                case 0:
                    var rt = "平手";
                    break;
            }
            return (
                rt +
                ug +
                " : " +
                cgg
            );
        }

        function uok() {
            cgg = cg();
            if (cgg > 21) {
                cf = true;
            } else {
                cf = false;
            }
            if (ug > 21) {
                uf = true;
            } else {
                uf = false;
            }
            if (cf || uf) {
                if (cf && uf) {
                    i("ab").innerHTML = er(0);
                } else {
                    if (cf) {
                        i("ab").innerHTML = er(1);
                    } else {
                        i("ab").innerHTML = er(2);
                    }
                }
            } else {
                if (ug == cgg) {
                    i("ab").innerHTML = er(0);
                } else {
                    if (ug > cgg) {
                        i("ab").innerHTML = er(1);
                    } else {
                        i("ab").innerHTML = er(2);
                    }
                }
            }
            ug = 0;
        }
    </script>
</head>

<body>
    <button id="aa" onclick="howToPlay()">?</button>
    <h2 id="ab">0</h2>
    <div id="uip">
        <button onclick="inp(1)">add</button>
        <button onclick="inp(2)">re</button>
        <button onclick="inp(3)">ok</button>
    </div>
</body>

</html>